/*
@author: feng
@date: 2022/6/19 17:00
@Version: 1.0
@last modifined by : 2022/6/19 17:00
@last Modifined time : 2022/6/19 17:00
*/

import { configureStore } from '@reduxjs/toolkit';

// 参考链接: https://webpack.js.org/guides/dependency-management/#requirecontext
const storeModuleFile = require.context('../store', true, /\.js$/);
const result = storeModuleFile.keys().map(storeModuleFile).reduce((total, item, index) => {
  const path = storeModuleFile.keys()[index];
  const res = new RegExp(/(\S+\/)(\S+)\.js/img);
  const name = (res.exec(path) || [])[2];
  // 排除非切片文件
  if (name !== 'index' && item.default) {
    total[name] = item.default;
  }
  return total;
}, {});

const store = configureStore({
  reducer: { ...result },
});

export default store;
